package org.jks.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jks.config.Config;
import org.jks.model.Category;
import org.jks.service.impl.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Component
@Scope("singleton")
@Controller
@RequestMapping("/config")
public class ConfigController {
	
	private static CategoryServiceImpl categoryImpl;
	@Autowired
	public ConfigController(CategoryServiceImpl categoryImpl){
		ConfigController.categoryImpl = categoryImpl;
	}
	
	public static List<Category> getCategories(){
		return categoryImpl.all();
	}
	
	@RequestMapping("/index")
	public ModelAndView index(HttpServletRequest request,
			HttpServletResponse response, HttpSession session,
			Map<String, Object> model) {
		Config.init(request, response, session, model, 0);
		return new ModelAndView("config/index", model);
	}
}
